﻿using Base.Core20;
using Base.Core20.Context;
using Base.Core20.DbRepos;
using Base.Core20.Enums;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Winservice.demo.Common;
using Winservice.demo.Models.Entities;
using Winservice.demo.Queue;

namespace A5.TaskSer.Services.Implements
{
    /// <summary>
    /// TaskApproval_Service-服务类
    /// </summary>
    public class TaskApproval_Service : RepoContext<QueueTask>
    {
        public TaskApproval_Service() : base(Utils.CreateInstance().ReadConnectionStrOfDataBase(), Utils.CreateInstance().ReadTypeOfDataBase()) { }

        /// <summary>
        /// 修改 任务审批 状态
        /// </summary>
        /// <param name="taskApprovalID"></param>
        /// <param name="taskStatusEnum"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public async Task<int> UpdateTaskApprovalStatusAsync(long taskApprovalID, FLOW_TASK_STATUS_Enum taskStatusEnum, string notes)
        {
            DateTime currentNow = DateTime.Now;

            string sql = string.Empty;
            if (taskStatusEnum == FLOW_TASK_STATUS_Enum.QUEUE_IN)
            {
                sql += "Q_START_DATE = @DATE,";
            }
            else if (taskStatusEnum == FLOW_TASK_STATUS_Enum.QUEUE_OUT)
            {
                sql += "Q_END_DATE = @DATE,";
            }
            else if (taskStatusEnum == FLOW_TASK_STATUS_Enum.END)
            {
                sql += "END_DATE = @DATE,";
            }
            else if (taskStatusEnum == FLOW_TASK_STATUS_Enum.AUTO_END)
            {
                sql += "AUTO_END_DATE = @DATE,";
            }
            else if (taskStatusEnum == FLOW_TASK_STATUS_Enum.EXCEPTION)
            {
                sql += "FAILED_DATE = @DATE,";
            }

            string sqlStr = string.Format(@"update FLOW_TASK
set
FLOW_TASK_STATUS = @FLOW_TASK_STATUS,
{0}
NOTES = @NOTES
where ID = @TaskApprovalID", sql);
            return await ExecuteAsync(sqlStr,
                new
                {
                    TaskApprovalID = taskApprovalID,
                    DATE = currentNow,
                    FLOW_TASK_STATUS = taskStatusEnum.GetHashCode(),
                    NOTES = notes
                });
        }

        /// <summary>
        /// 查询 任务审批 信息（查询前20条） FLOW_TASK_STATUS=102
        /// </summary>
        /// <returns></returns>
        public async Task<IEnumerable<QueueTask>> GetTaskApproval()
        {
            string sqlStr = @"
select
top 20
a.ID FLOW_TASK_ID,
a.FLOW_INCIDENT_ID,
b.PROCESS_NAME,
b.INCIDENT,
b.SUMMARY,
a.TASK_ID,
a.STEP_LABEL,
a.OPINION,
c.[user_id] OPERATOR_ID,
c.user_guid OPERATOR_GUID,
c.user_loginname OPERATOR_ACCOUNT,
a.IS_END_STEP,
a.CURRENT_STEP_KEY,
e.FLOW_TYPE,
a.BUTTON_TYPE,
b.[PROCESS_DEFINITION_ID],
b.[BUSINESS_KEY],
VARIABLES=(
isnull((
select a1.NAME + ':' + a1.VAL + ':' + CONVERT(VARCHAR(10), a1.VARIABLE_TYPE) + ':' + CONVERT(VARCHAR(10), a1.SORT) + '|' from FLOW_VARIABLES(nolock) a1
WHERE a1.FLOW_INCIDENT_ID=a.FLOW_INCIDENT_ID and a1.TASK_ID=a.TASK_ID
--ORDER BY aa.TaskId
ORDER BY a1.SORT ASC
FOR XML PATH('')),'')
),
isnull(d.FIRST_SIGN_COUNT, 0) FIRST_SIGN_COUNT,
isnull(d.SIGN_TYPE, 2) SIGN_TYPE,
SIGN_TASKS=(
isnull((
select a1.TASK_ID + ':' + CONVERT(VARCHAR(10), a1.FLOW_TASK_STATUS) + ':' + CONVERT(VARCHAR(10), a1.OPINION) + '|' from FLOW_TASK(nolock) a1
WHERE a1.FLOW_INCIDENT_ID=a.FLOW_INCIDENT_ID and a1.CURRENT_STEP_KEY=a.CURRENT_STEP_KEY and a1.IS_CURRENT_SIGN_PATCH=0
--ORDER BY a1.TaskId
ORDER BY a1.MODIFY_DATE ASC
FOR XML PATH('')),'')
)
from FLOW_TASK(nolock) a
inner join FLOW_INCIDENT(nolock) b
on b.ID=a.FLOW_INCIDENT_ID
inner join V_OC_USERS(nolock) c
on c.[user_id]=a.MODIFY_USER
inner join FLOW_QUEUE(nolock) e
on e.FLOW_INCIDENT_ID = a.FLOW_INCIDENT_ID and e.TASK_ID=a.TASK_ID
and e.FLOW_TYPE=1  --0:Ult; 1:A5;
left join FLOW_COUNTERSIGN(nolock) d
on d.FLOW_INCIDENT_ID=a.FLOW_INCIDENT_ID and d.SIGN_KEY=a.CURRENT_STEP_KEY
where e.DEL_STATUS=0 and a.FLOW_TASK_STATUS=102 and b.FLOW_INCIDENT_STATUS=102
order by a.MODIFY_DATE asc
";
            return await QueryAsync<QueueTask>(sqlStr);
        }

        /// <summary>
        /// 根据 IncidentID 及 SignKey 判断 会签节点 是否 已经办结了 
        /// </summary>
        /// <param name="queueTask"></param>
        /// <returns></returns>
        public async Task<SignFinished> GetSignFinished(QueueTask queueTask)
        {
            string sqlStr = @"
SELECT top 1 a.[ID] FROM [FLOW_COUNTERSIGN_FINISHED] a
where a.FLOW_INCIDENT_ID=@FLOW_INCIDENT_ID
and a.SIGN_KEY=@SIGN_KEY";
            return await QuerySingleAsync<SignFinished>(sqlStr, new
            {
                FLOW_INCIDENT_ID = queueTask.FLOW_INCIDENT_ID,
                SIGN_KEY = queueTask.CURRENT_STEP_KEY
            });
        }

        /// <summary>
        /// 设置 会签节点已经结束 后的 操作
        /// 1. 把 IncidentID 及 SIGN_KEY 插入 FLOW_COUNTERSIGN_FINISHED
        /// 2. 再 根据 IncidentID 及 SIGN_KEY 把 FLOW_TASK 中的 IS_CURRENT_SIGN_PATCH 修改 成 1
        /// </summary>
        /// <param name="queueTask"></param>
        /// <returns></returns>
        public async Task<int> UpdateSignStepIsFinishedAsync(QueueTask queueTask)
        {
            //当前的时间
            DateTime currentNow = DateTime.Now;
            List<SqlOper> sqlOperList = new List<SqlOper>();
            sqlOperList.Add(new SqlOper()
            {
                // 1. INSERT FLOW_COUNTERSIGN_FINISHED
                SQL = @"insert into FLOW_COUNTERSIGN_FINISHED
(ID, CREATE_DATE, CREATE_USER, MODIFY_DATE, MODIFY_USER, DEL_STATUS, FLOW_INCIDENT_ID, SIGN_KEY, NOTES)
values
(@ID, @CREATE_DATE, @CREATE_USER, @MODIFY_DATE, @MODIFY_USER, @DEL_STATUS, @FLOW_INCIDENT_ID, @SIGN_KEY, @NOTES)",
                PARAM = new
                {
                    ID = PrimaryKey.GetInstance.Id(),
                    CREATE_DATE = currentNow,
                    CREATE_USER = queueTask.OPERATOR_ID,
                    MODIFY_DATE = currentNow,
                    MODIFY_USER = queueTask.OPERATOR_ID,
                    DEL_STATUS = 0,
                    FLOW_INCIDENT_ID = queueTask.FLOW_INCIDENT_ID,
                    SIGN_KEY = queueTask.CURRENT_STEP_KEY,
                    NOTES = string.Empty
                }
            });

            sqlOperList.Add(new SqlOper()
            {
                // 2. UPDATE FLOW_TASK
                SQL = @"update FLOW_TASK
set
IS_CURRENT_SIGN_PATCH = @IS_CURRENT_SIGN_PATCH
where FLOW_INCIDENT_ID = @FLOW_INCIDENT_ID and CURRENT_STEP_KEY = @CURRENT_STEP_KEY",
                PARAM = new
                {
                    IS_CURRENT_SIGN_PATCH = 1,
                    FLOW_INCIDENT_ID = queueTask.FLOW_INCIDENT_ID,
                    CURRENT_STEP_KEY = queueTask.CURRENT_STEP_KEY
                }
            });

            return await TransOperationAsync(sqlOperList);
        }

        /// <summary>
        /// 获得实例号 并 修改 FLOW_INCIDENT
        /// </summary>
        /// <param name="incidentID"></param>
        /// <param name="incident"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public async Task<int> UpdateIncidentNoAsync(long incidentID, string incident, string notes)
        {
            DateTime currentNow = DateTime.Now;
            string sqlStr = @"update FLOW_INCIDENT
set INCIDENT=@INCIDENT,
INCIDENT_DATE=@INCIDENT_DATE,
NOTES=@NOTES
where ID=@ID";
            return await ExecuteAsync(sqlStr,
                new
                {
                    INCIDENT = incident,
                    INCIDENT_DATE = currentNow,
                    NOTES = notes,
                    ID = incidentID
                });
        }

        /// <summary>
        /// 修改 Flow_Incident 状态 = End
        /// </summary>
        /// <param name="incidentID"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public async Task<int> UpdateIncidentStatusIsEndAsync(long incidentID, string notes)
        {
            DateTime currentNow = DateTime.Now;
            string sqlStr = @"update FLOW_INCIDENT
set FLOW_INCIDENT_STATUS=@FLOW_INCIDENT_STATUS,
END_DATE=@END_DATE,
NOTES=@NOTES
where ID=@ID";
            return await ExecuteAsync(sqlStr,
                new
                {
                    FLOW_INCIDENT_STATUS = FLOW_INCIDENT_STATUS_Enum.END.GetHashCode(),
                    END_DATE = currentNow,
                    NOTES = notes,
                    ID = incidentID
                });
        }

        /// <summary>
        /// 设置 异常状态
        /// 1. 根据 IncidentID FLOW_INCIDENT FLOW_INCIDENT_STATUS = 1099
        /// 2. 根据 TaskApprovalID FLOW_TASK FLOW_TASK_STATUS = 1099
        /// </summary>
        /// <param name="incidentID"></param>
        /// <param name="taskApprovalID"></param>
        /// <param name="notes"></param>
        /// <returns></returns>
        public async Task<int> UpdateStatusIsExceptionAsync(long incidentID, long taskApprovalID, string notes)
        {
            //当前的时间
            DateTime currentNow = DateTime.Now;
            List<SqlOper> sqlOperList = new List<SqlOper>();
            sqlOperList.Add(new SqlOper()
            {
                // 1. UPDATE FLOW_INCIDENT
                SQL = @"update FLOW_INCIDENT
set 
FLOW_INCIDENT_STATUS = @FLOW_INCIDENT_STATUS
where ID = @ID",
                PARAM = new
                {
                    ID = incidentID,
                    FLOW_INCIDENT_STATUS = FLOW_INCIDENT_STATUS_Enum.EXCEPTION.GetHashCode()
                }
            });

            sqlOperList.Add(new SqlOper()
            {
                // 2. UPDATE FLOW_TASK
                SQL = @"update FLOW_TASK
set
FLOW_TASK_STATUS = @FLOW_TASK_STATUS,
FAILED_DATE = @DATE,
NOTES = @NOTES
where ID = @ID",
                PARAM = new
                {
                    ID = taskApprovalID,
                    FLOW_TASK_STATUS = FLOW_TASK_STATUS_Enum.EXCEPTION.GetHashCode(),
                    DATE = currentNow,
                    NOTES = notes
                }
            });
            return await TransOperationAsync(sqlOperList);
        }

        /// <summary>
        /// 查询已经完成的流程信息
        /// </summary>
        /// <returns></returns>
        public async Task<IEnumerable<FLOW_INCIDENT_FINISHED>> GetFinishedIncidentByA5Async()
        {
            string sql = @"
select 
rtrim(a.NAME_) PROCESS_NAME
, a.PROC_INST_ID_ INCIDENT
, a.[STATUS]
from 
[A5_V_PROC_ARCHIVED](nolock) a
where exists(
select b.PROCESS_NAME, b.INCIDENT, b.FLOW_INCIDENT_STATUS from FLOW_INCIDENT(nolock) b
where b.DEL_STATUS=0 and b.FLOW_INCIDENT_STATUS=102
and b.PROCESS_NAME=a.NAME_
and b.INCIDENT=a.PROC_INST_ID_
)
order by a.PROCINST_END_TIME_";
            return await QueryAsync<FLOW_INCIDENT_FINISHED>(sql);
        }

        /// <summary>
        /// 设置 自定义 流程
        /// </summary>
        /// <param name="processName">流程名称</param>
        /// <param name="incident">流程实例</param>
        /// <param name="sql">sql</param>
        /// <returns></returns>
        public async Task<int> SetCustomProcess(string processName, string incident, string sql)
        {
            return await ExecuteAsync(sql,
                new
                {
                    PROCESS_NAME = processName,
                    INCIDENT = incident
                });
        }

        /// <summary>
        /// 设置 流程 已经结束
        /// </summary>
        /// <param name="processName">流程名称</param>
        /// <param name="incident">流程实例</param>
        /// <returns></returns>
        public async Task<int> SetIncidentIsEnd(string processName, string incident)
        {
            DateTime currentNow = DateTime.Now;
            string sqlStr = @"update FLOW_INCIDENT
set [FLOW_INCIDENT_STATUS]=103,
END_DATE=@END_DATE
where PROCESS_NAME=@PROCESS_NAME and INCIDENT=@INCIDENT";
            return await ExecuteAsync(sqlStr,
                new
                {
                    END_DATE = currentNow,
                    PROCESS_NAME = processName,
                    INCIDENT = incident
                });
        }

        /// <summary>
        /// 设置 流程 已经中止
        /// </summary>
        /// <param name="processName">流程名称</param>
        /// <param name="incident">流程实例</param>
        /// <returns></returns>
        public async Task<int> SetIncidentIsAbort(string processName, string incident)
        {
            DateTime currentNow = DateTime.Now;
            string sqlStr = @"update FLOW_INCIDENT
set [FLOW_INCIDENT_STATUS]=104,
ABORT_DATE=@ABORT_DATE
where PROCESS_NAME=@PROCESS_NAME and INCIDENT=@INCIDENT";
            return await ExecuteAsync(sqlStr,
                new
                {
                    ABORT_DATE = currentNow,
                    PROCESS_NAME = processName,
                    INCIDENT = incident
                });
        }

        /// <summary>
        /// 查询 180 天前的所有 已经 办结或者撤销的流程（103,104）
        /// </summary>
        /// <param name="daysByDelete"></param>
        /// <returns></returns>
        public async Task<IEnumerable<FLOW_INCIDENT_DELETE>> GetDeleteIncidentIDAsync(string daysByDelete)
        {
            string sql = @"select a.ID FLOW_INCIDENT_ID, a.CREATE_DATE
from[FLOW_INCIDENT](nolock) a
where 1=1
and a.FLOW_INCIDENT_STATUS in (103, 104)
and a.CREATE_DATE < DATEADD(day, -" + daysByDelete + @", getdate())
order by a.CREATE_DATE asc";
            return await QueryAsync<FLOW_INCIDENT_DELETE>(sql);
        }

        /// <summary>
        /// 根据 实例ID 转移 或 删除 相关业务表信息
        /// </summary>
        /// <param name="incidentID"></param>
        /// <returns></returns>
        public async Task<int> DeleteInfoByIncidentID(long incidentID)
        {
            List<SqlOper> sqlOperList = new List<SqlOper>();
            sqlOperList.Add(new SqlOper()
            {
                // 1. FLOW_STEPUSER_HISTORY         新增 FLOW_STEPUSER 表 根据 FLOW_INCIDENT_ID 即 ID
                SQL = @"
INSERT INTO [FLOW_STEPUSER_HISTORY]
           ([ID]
           ,[CREATE_DATE]
           ,[CREATE_USER]
           ,[DEL_STATUS]
           ,[FLOW_INCIDENT_ID]
           ,[MODIFY_DATE]
           ,[MODIFY_USER]
           ,[NOTES]
           ,[STEP_LABEL]
           ,[USER_ACCOUNT])
select
a.[ID]
,a.[CREATE_DATE]
,a.[CREATE_USER]
,a.[DEL_STATUS]
,a.[FLOW_INCIDENT_ID]
,a.[MODIFY_DATE]
,a.[MODIFY_USER]
,a.[NOTES]
,a.[STEP_LABEL]
,a.[USER_ACCOUNT]
from FLOW_STEPUSER(nolock) a
where a.[FLOW_INCIDENT_ID]=@FLOW_INCIDENT_ID
",
                PARAM = new { FLOW_INCIDENT_ID = incidentID }
            });
            sqlOperList.Add(new SqlOper()
            {
                // 2. FLOW_TASK_HISTORY             新增 FLOW_TASK     表 根据 FLOW_INCIDENT_ID 即 ID
                SQL = @"
INSERT INTO [FLOW_TASK_HISTORY]
           ([ID]
           ,[AUTO_END_DATE]
           ,[COMMENTS]
           ,[CREATE_DATE]
           ,[CREATE_USER]
           ,[CURRENT_STEP_KEY]
           ,[DEL_STATUS]
           ,[END_DATE]
           ,[FAILED_DATE]
           ,[FLOW_INCIDENT_ID]
           ,[FLOW_TASK_STATUS]
           ,[IP]
           ,[IS_CURRENT_PATCH]
           ,[IS_CURRENT_SIGN_PATCH]
           ,[IS_END_STEP]
           ,[MODIFY_DATE]
           ,[MODIFY_USER]
           ,[NOTES]
           ,[OPINION]
           ,[Q_END_DATE]
           ,[Q_START_DATE]
           ,[SAVE_DATE]
           ,[SEND_DATE]
           ,[SIGNATURE_IMAGE]
           ,[STEP_LABEL]
           ,[TASK_ID]
           ,[BUTTON_TYPE])
select 
           a.[ID]
           ,a.[AUTO_END_DATE]
           ,a.[COMMENTS]
           ,a.[CREATE_DATE]
           ,a.[CREATE_USER]
           ,a.[CURRENT_STEP_KEY]
           ,a.[DEL_STATUS]
           ,a.[END_DATE]
           ,a.[FAILED_DATE]
           ,a.[FLOW_INCIDENT_ID]
           ,a.[FLOW_TASK_STATUS]
           ,a.[IP]
           ,a.[IS_CURRENT_PATCH]
           ,a.[IS_CURRENT_SIGN_PATCH]
           ,a.[IS_END_STEP]
           ,a.[MODIFY_DATE]
           ,a.[MODIFY_USER]
           ,a.[NOTES]
           ,a.[OPINION]
           ,a.[Q_END_DATE]
           ,a.[Q_START_DATE]
           ,a.[SAVE_DATE]
           ,a.[SEND_DATE]
           ,a.[SIGNATURE_IMAGE]
           ,a.[STEP_LABEL]
           ,a.[TASK_ID]
           ,a.[BUTTON_TYPE]
from FLOW_TASK(nolock) a
where a.FLOW_INCIDENT_ID=@FLOW_INCIDENT_ID
",
                PARAM = new { FLOW_INCIDENT_ID = incidentID }
            });
            sqlOperList.Add(new SqlOper()
            {
                // 3. FLOW_INCIDENT_HISTORY         新增 FLOW_INCIDENT 表 根据 FLOW_INCIDENT_ID 即 ID
                SQL = @"
INSERT INTO [FLOW_INCIDENT_HISTORY]
           ([ID]
           ,[ABORT_DATE]
           ,[BUSINESS_KEY]
           ,[CREATE_DATE]
           ,[CREATE_USER]
           ,[DEL_STATUS]
           ,[END_DATE]
           ,[FIRST_SAVE_DATE]
           ,[FIRST_SEND_DATE]
           ,[FLOW_INCIDENT_STATUS]
           ,[INCIDENT]
           ,[INCIDENT_DATE]
           ,[MODIFY_DATE]
           ,[MODIFY_USER]
           ,[NOTES]
           ,[PARENT_FLOW_INCIDENT_ID]
           ,[PROCESS_DEFINITION_ID]
           ,[PROCESS_NAME]
           ,[SUMMARY]
           ,[VER])
select 
           a.[ID]
           ,a.[ABORT_DATE]
           ,a.[BUSINESS_KEY]
           ,a.[CREATE_DATE]
           ,a.[CREATE_USER]
           ,a.[DEL_STATUS]
           ,a.[END_DATE]
           ,a.[FIRST_SAVE_DATE]
           ,a.[FIRST_SEND_DATE]
           ,a.[FLOW_INCIDENT_STATUS]
           ,a.[INCIDENT]
           ,a.[INCIDENT_DATE]
           ,a.[MODIFY_DATE]
           ,a.[MODIFY_USER]
           ,a.[NOTES]
           ,a.[PARENT_FLOW_INCIDENT_ID]
           ,a.[PROCESS_DEFINITION_ID]
           ,a.[PROCESS_NAME]
           ,a.[SUMMARY]
           ,a.[VER]
from FLOW_INCIDENT(nolock) a
where a.ID=@FLOW_INCIDENT_ID
",
                PARAM = new { FLOW_INCIDENT_ID = incidentID }
            });
            sqlOperList.Add(new SqlOper()
            {
                // 4. QUEUE_TASK                    删除 根据 STATUS=103 并且 THIRD_ID<>''
                SQL = @"delete from QUEUE_TASK where [STATUS]=103 and THIRD_ID<>''"
            });
            sqlOperList.Add(new SqlOper()
            {
                // 5. QUEUE_TASK                     删除 根据 STATUS=103 并且 THIRD_ID = FLOW_TASK 中的 FLOW_INCIDENT_ID 的 103 或者 104
                SQL = @"delete from QUEUE_TASK 
where [STATUS]=103 
and THIRD_ID in (select a.TASK_ID from FLOW_TASK(nolock) a
where a.FLOW_INCIDENT_ID=@FLOW_INCIDENT_ID
)",
                PARAM = new { FLOW_INCIDENT_ID = incidentID }
            });
            sqlOperList.Add(new SqlOper()
            {
                // 6. FLOW_QUEUE                    删除 根据 FLOW_INCIDENT_ID
                SQL = @"delete from FLOW_QUEUE where FLOW_INCIDENT_ID=@FLOW_INCIDENT_ID",
                PARAM = new { FLOW_INCIDENT_ID = incidentID }
            });
            sqlOperList.Add(new SqlOper()
            {
                // 7. FLOW_VARIABLES                    删除 根据 FLOW_INCIDENT_ID
                SQL = @"delete from FLOW_VARIABLES where FLOW_INCIDENT_ID=@FLOW_INCIDENT_ID",
                PARAM = new { FLOW_INCIDENT_ID = incidentID }
            });
            sqlOperList.Add(new SqlOper()
            {
                // 8. FLOW_COUNTERSIGN_FINISHED                    删除 根据 FLOW_INCIDENT_ID
                SQL = @"delete from FLOW_COUNTERSIGN_FINISHED where FLOW_INCIDENT_ID=@FLOW_INCIDENT_ID",
                PARAM = new { FLOW_INCIDENT_ID = incidentID }
            });
            sqlOperList.Add(new SqlOper()
            {
                // 9. FLOW_COUNTERSIGN                    删除 根据 FLOW_INCIDENT_ID
                SQL = @"delete from FLOW_COUNTERSIGN where FLOW_INCIDENT_ID=@FLOW_INCIDENT_ID",
                PARAM = new { FLOW_INCIDENT_ID = incidentID }
            });
            sqlOperList.Add(new SqlOper()
            {
                // 10. FLOW_STEPUSER                    删除 根据 FLOW_INCIDENT_ID
                SQL = @"delete from FLOW_STEPUSER where FLOW_INCIDENT_ID=@FLOW_INCIDENT_ID",
                PARAM = new { FLOW_INCIDENT_ID = incidentID }
            });
            sqlOperList.Add(new SqlOper()
            {
                // 11. FLOW_TASK                    删除 根据 FLOW_INCIDENT_ID
                SQL = @"delete from FLOW_TASK where FLOW_INCIDENT_ID=@FLOW_INCIDENT_ID",
                PARAM = new { FLOW_INCIDENT_ID = incidentID }
            });
            sqlOperList.Add(new SqlOper()
            {
                // 12. FLOW_INCIDENT                    删除 根据 FLOW_INCIDENT_ID
                SQL = @"delete from FLOW_INCIDENT where ID=@FLOW_INCIDENT_ID",
                PARAM = new { FLOW_INCIDENT_ID = incidentID }
            });
            return await TransOperationAsync(sqlOperList);
        }

        /// <summary>
        /// 增加 终止 流程 记录
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> LogAbortRecordAsync(LOG_ABORTED model)
        {
            string sql = await InsertCommandTextAsync<LOG_ABORTED>(model);
            return await ExecuteAsync(sql, model);
        }




    }
}
